<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateDepartmentsTable extends Migration
{
    /**
     * Run the migrations.
     * 部门表
     * @return void
     */
    public function up()
    {
        Schema::create('departments', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('mark')->comment('部门编号');
            $table->string('name')->comment('部门名称');
            $table->integer('parent_id')->unsigned()->comment('部门父ID')->default(0);
            $table->text('description')->comment('部门描述')->nullable();
            $table->string('full_name')->comment('部门全称')->nullable();
            $table->string('memo_code')->comment('助记码')->nullable();
            $table->integer('organization_id')->unsigned()->comment('所属组织')->nullable();
            $table->foreign('organization_id')->references('id')->on('organizations')->onDelete('set null');
            // $table->integer('use_organ_id')->comment('使用组织');
            $table->text('creator')->comment('创建人')->nullable();
            //$table->dateTime('create_time')->comment('创建时间');
            $table->text('disable')->comment('禁用人')->nullable();
            //$table->dateTime('disable_time')->comment('禁用时间');
            $table->boolean('data_state')->comment('数据状态 0未审核 1已审核')->default(0);
            $table->boolean('disabled_state')->comment('禁用状态 0反禁用-启用 1禁用')->default(0);
            $table->softDeletes();
            $table->timestamps();
            $table->unique(['name','deleted_at']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('departments');
    }
}
